package engine.step;

import engine.GameEngine;
import engine.UnitAction;
import engine.data.Player;
import engine.data.Unit;
import engine.data.UnitType;

public final class CheckUnitsStep extends Step {

	private static Step step;

	public static synchronized Step getStep() {
		if (step == null)
			step = new CheckUnitsStep();
		return step;
	}

	public Step execute() {
		Player currPlayer = GameEngine.currPlayer;
		Unit unit;
		for (short index = 0; index < currPlayer.units.size(); index++) {
			unit = (Unit) currPlayer.units.get(index);
			if (unit.action != UnitAction.NONE && unit.actionDone) {
				UnitAction.actionDone(GameEngine.map.getTile(unit.x, unit.y), unit);
				GameEngine.map.refreshRangeImages(currPlayer, unit.x, unit.y, UnitType.getRP(unit.type), false);
				currPlayer.controller.onActionDone(unit);
			}
		}
		return CheckTechnologyStep.getStep();
	}
}
